package com.blockmeta.bbs.businesslibrary.widget.chartview;


import buf.Kline;


public class CandleData {
    public long m_nDate;
    //    public int m_nTime;
    private double m_dbOpen;
    private double m_dbHigh;
    private double m_dbLow;
    private double m_dbClose;


    public float m_lVolume;
    public double m_dbAvgPx;
    public int m_nTrddate;
    public boolean m_bDrawDot = false;
    public boolean m_bQuoteupdate = false;

    private double m_dbOpenForward;
    private double m_dbHighForward;
    private double m_dbLowForward;
    private double m_dbCloseForward;


    private double m_dbOpenBackward;
    private double m_dbHighBackward;
    private double m_dbLowBackward;
    private double m_dbCloseBackward;

    public boolean m_fake;

    public CandleData() {
        m_lVolume = 0;
    }

    public CandleData(Kline.KlineListItem chart) {
        update(chart);
    }


    public CandleData(float price, float volumn) {
        m_dbClose = price;
        m_lVolume = volumn;
    }

    public CandleData(long date, float volumn) {
        m_nDate = date;
        m_lVolume = volumn;
    }

    public CandleData(int date, int time, double price, long vol, int trddate) {
        this(date, time, price, vol, 0, trddate);
    }

    public CandleData(int date, int time, double price, long vol, double avgPx, int trddate) {
        m_nDate = date;
//        m_nTime = time;
        m_dbOpen = price;
        m_dbHigh = price;
        m_dbLow = price;
        m_dbClose = price;
        m_lVolume = vol;
        m_dbAvgPx = avgPx;
        m_nTrddate = trddate;
    }

    public CandleData(long date, double price, float vol) {
        m_nDate = date;
        m_dbClose = price;
        m_lVolume = vol;
    }

    public long getDate() {
        return m_nDate;
    }

    public void setDate(long m_nDate) {
        this.m_nDate = m_nDate;
    }

    public boolean isFake() {
        return m_fake;
    }

    public boolean compare(CandleData candle) {
        if (m_nDate == candle.m_nDate || m_dbOpen == candle.m_dbOpen || m_dbHigh == candle.m_dbHigh || m_dbLow == candle.m_dbLow || m_dbClose == candle.m_dbClose || m_lVolume == candle.m_lVolume || m_nTrddate == candle.m_nTrddate) {
            return true;
        }
        return false;
    }

    public void update(CandleData candle) {
        this.m_nDate = candle.m_nDate;
        this.m_dbOpen = candle.m_dbOpen;
        this.m_dbHigh = candle.m_dbHigh;
        this.m_dbLow = candle.m_dbLow;
        this.m_dbClose = candle.m_dbClose;
        this.m_lVolume = candle.m_lVolume;
        this.m_dbAvgPx = candle.m_dbAvgPx;
        this.m_nTrddate = candle.m_nTrddate;
        this.m_fake = candle.m_fake;

        //forward
        m_dbHighForward = candle.m_dbHighForward;
        m_dbOpenForward = candle.m_dbOpenForward;
        m_dbLowForward = candle.m_dbLowForward;
        m_dbCloseForward = candle.m_dbCloseForward;

        //backward
        m_dbHighBackward = candle.m_dbHighBackward;
        m_dbOpenBackward = candle.m_dbOpenBackward;
        m_dbLowBackward = candle.m_dbLowBackward;
        m_dbCloseBackward = candle.m_dbCloseBackward;

    }


    public void update(Kline.KlineListItem chart) {
        m_nDate = chart.getDate();

        m_dbOpen = chart.getOpen();

        m_dbHigh = chart.getHigh();

        m_dbLow = chart.getLow();
        m_dbClose = chart.getClose();
        m_lVolume = chart.getVol();
//		m_nTime = chart.m_time;
//			m_dbAvgPx = chart.m_avgpx;

//			m_nTrddate = chart.m_trddate;


//        toLog();

    }

    public CandleData clone() {
        CandleData tData = new CandleData();
        tData.update(this);
        return tData;
    }

    public void toLog() {
//        LogUtils.d("chen", getLog()
//        );
    }

    public String getLog()
    {
        return "Date:" + m_nDate + ", Open:" + m_dbOpen +
                ", High:" + m_dbHigh + ", Low:" + m_dbLow + ", Close:" + m_dbClose + ", m_dbAvgPx:" + m_dbAvgPx
                + "，openforward:" + m_dbOpenForward + ",closeforward:" + m_dbCloseForward + ",lowforward:" + m_dbLowForward + ",highforward:" + m_dbHighForward +
                "，openBackward:" + m_dbOpenBackward + ",closeBackward:" + m_dbCloseBackward + ",lowBackward:" + m_dbLowBackward + ",highBackward:" + m_dbHighBackward;
    }


    public double getDbOpen() {
        return m_dbOpen;
    }

    public double getDbHigh() {
        return m_dbHigh;
    }


    public double getDbLow() {

        return m_dbLow;
    }

    public double getDbClose() {
        return m_dbClose;
    }

    public void setDbOpen(double m_dbOpen) {
        this.m_dbOpen = m_dbOpen;
    }

    public void setDbHigh(double m_dbHigh) {
        this.m_dbHigh = m_dbHigh;
    }

    public void setDbLow(double m_dbLow) {
        this.m_dbLow = m_dbLow;
    }

    public void setDbClose(double m_dbClose) {
        this.m_dbClose = m_dbClose;
    }


    public double getOpenForward() {
        return m_dbOpenForward;
    }

    public double getHighForward() {
        return m_dbHighForward;
    }

    public double getLowForward() {
        return m_dbLowForward;
    }

    public double getCloseForward() {
        return m_dbCloseForward;
    }

    public double getOpenBackward() {
        return m_dbOpenBackward;
    }

    public double getHighBackward() {
        return m_dbHighBackward;
    }

    public double getLowBackward() {
        return m_dbLowBackward;
    }

    public double getCloseBackward() {
        return m_dbCloseBackward;
    }


    public void setOpenForward(double m_dbOpenForward) {
        this.m_dbOpenForward = m_dbOpenForward;
    }

    public void setHighForward(double m_dbHighForward) {
        this.m_dbHighForward = m_dbHighForward;
    }

    public void setLowForward(double m_dbLowForward) {
        this.m_dbLowForward = m_dbLowForward;
    }

    public void setCloseForward(double m_dbCloseForward) {
        this.m_dbCloseForward = m_dbCloseForward;
    }

    public void setOpenBackward(double m_dbOpenBackward) {
        this.m_dbOpenBackward = m_dbOpenBackward;
    }

    public void setHighBackward(double m_dbHighBackward) {
        this.m_dbHighBackward = m_dbHighBackward;
    }

    public void setLowBackward(double m_dbLowBackward) {
        this.m_dbLowBackward = m_dbLowBackward;
    }

    public void setCloseBackward(double m_dbCloseBackward) {
        this.m_dbCloseBackward = m_dbCloseBackward;
    }

    public double getdbOpenBackward() {
        return m_dbOpenBackward;
    }

    public void setdbOpenBackward(double m_dbOpenBackward) {
        this.m_dbOpenBackward = m_dbOpenBackward;
    }

    public double getdbCloseBackward() {
        return m_dbCloseBackward;
    }

    public void setdbCloseBackward(double m_dbCloseBackward) {
        this.m_dbCloseBackward = m_dbCloseBackward;
    }

    public void updateHighLowClose(double price) {
        if (price > getDbHigh())
            setDbHigh(price);

        if (price < getDbLow())
            setDbLow(price);

        setDbClose(price);
    }
}


